 
console.log(location.search)

 // $post("http://www.bai.com/info",'',datafn);


   var url="http://www.bai.com";
 // request(url+'/'+'nurse',0);
 seletTab("#worktype","li","active_red");
 seletTab("#shu_name","li","active_red");
 seletTab("#age-rang","li","active_red");
 seletTab("#worktime_rang","li","active_red");

$(".item_ul li").click(function () {
    var  num2=$(this).index();
    choice(num2);

});
function choice(e) {
    $(".item_ul li").eq(e).addClass("activee").siblings().removeClass("activee");
    $(".job_box>div").eq(e).addClass("job_detail").siblings().removeClass("job_detail");
    request(url+'/'+'nurse',e);
}
//判断显示何种职业
function page() {
    var num3=0;
    switch (location.search){
        case "?0":
            num3=0;
            break;
        case "?1":
            num3=1;
            break;
        case "?2":
            num3=2;
            break;
        case "?3":
            num3=3;
            break;
        case "":
            num3=0;
            break;
    }
    choice(num3);
}
page();

function request(e,b){
    console.log(e);
    $post(e,'',datafn);
//月嫂列表处理函数
    function datafn(data){
      
        if(data.code == 200){
            var dataa=data.data[b];
            var personList=dataa.dataList;
            $("#coverImg").attr("src",dataa.coverImg);
            $("#position").html(dataa.coverTitle);
            $("#coverTitle").html(dataa.coverTitle);
            $("#coverTitleEn").html(dataa.coverTitleEn);
            $("#coverInfo").html(dataa.coverInfo);
            var html = '';
            console.log(personList.length)
            if(personList.length>0){
                for(var i = 0 ; i < personList.length; i ++){
                    html+='<li>';
                    html+=' <a target="_blank" href="./yuesao_detail.html?id='+personList[i].id +'">';
                    html+='<img src="'+personList[i].imgsrc+'" alt="">';
                    html+='<div class="worker_info"><span class="name">'+personList[i].name +'</span><span class="job_class">'+personList[i].title;
                    html+='</span></div>';
                    html+='<div>';
                    html +='<p>资质：'+personList[i].worktime+'</p>';
                    html+=' <p class="text-showell">擅长：'+personList[i].good+'</p>';
                    html+=' <p>服务次数：'+personList[i].servenum+'次</p>';
                    html+=' </div>';
                    html +='</a>';
                    html+=' <div class="worker_function">';
                    html+='<span> <i class="icon iconfont icon-xinxing"></i>关注</span>';
                    html+='<span><a href="/swt" style="color: white"><i class="icon iconfont icon-shizhong"></i>预约</a></span>';
                    html+=' </div>';
                    html+='<div class="contrast">';
                    html+='  <span id="'+personList[i].id+'" data-types="'+personList[i].types+'"></span>对比';
                    html+='<div></li>';
                }
            }else{
                html="<p style='color:#646464;font-size:18px;padding:20px;height:150px;line-height:90px'>暂无相关数据！！！</p>"
            }
          
            //  把渲染好的数据添加到html 中去
            document.getElementById('personlists').innerHTML = html;
           //预约弹窗
            $("a").click(function () {
                console.log($(this).attr("href"));
                var href= $(this).attr("href");
                if(href=="/swt"){
                    var html='';
                    html+='<div class="swt_box"  style="position: fixed;top:100px;left:calc((100% - 500px) / 2);overflow: hidden;z-index: 9999; ">\n' +
                        '    <img src="images/swt.png" width="500"  usemap="#swt">\n' +
                        '    <map name="swt" id="swt">\n' +
                        '        <area shape="rect" coords="460,10,489,38" href="javascript:void(0);"  title="关闭提示" onclick="function close_swt(){$(\'.swt_box\').slideUp(400)};close_swt()">\n' +
                        '    </map>\n' +
                        '</div>';
                    $("body").append(html);
                    return false;
                }

            });
            var len  =  $("#personlists li").length;
            if(len>0){
                $("#conpar").show()
            }else{
                $("#conpar").hide()
            }
            // 添加对比
             var compareArr = [];
               $(".contrast span").click(function () {
                    var $id = $(this).attr("id");
                    var $type = $(this).attr("data-types");
                    var $data ={id:$id , type:$type}
                    console.log($data)
                    if ($(this).hasClass("activee")) {
                        $(this).removeClass("activee");
                      //  $post("http://delCompareByid",$data,datafn);
                    } else {
                        $(this).addClass("activee");
                       // $post("http://addCompareByid",$data,datafn);
                    }
                })
               function datafn(res){
                if(res.code == 200){
                    // 获取模板内容  在index页面定义的ID 
                    var tpl = document.getElementById('compare').innerHTML;
                    // 通过template(模板,数据)渲染数据
                    var html = template(tpl,{datalist:res.data});
                    //  把渲染好的数据添加到html 中去
                    document.getElementById('comparebox').innerHTML = html
                }
               }
        }
    };
}